package com.sy.controller;

import com.sy.constant.AppConstant;
import com.sy.dto.JsonResult;
import com.sy.sevice.UserService;
import com.sy.vo.LoginUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Monkey-D-Gu
 * @version 1.0
 * @date 2020/9/11 0011 14:01
 * @usage 登录注册相关的Controller控制器
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录操作
     *
     * @param loginUserVo 登录携带数据的Vo
     * @return JsonResult对象
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public JsonResult loginWithPower(@RequestBody LoginUserVo loginUserVo) {
        System.out.println(loginUserVo);
        Integer power = loginUserVo.getPower();
        System.out.println(1);
        JsonResult jsonResult;
        if (AppConstant.ADMIN_POWER_NUM.equals(power)) { //管理员权限
            jsonResult = userService.loginThroughAdmin(loginUserVo);
        } else if (AppConstant.TEACHER_POWER_NUM.equals(power)) { //老师权限
            jsonResult = userService.loginThroughTeacher(loginUserVo);
        } else if (AppConstant.STUDENT_POWER_NUM.equals(power)) { //学生权限
            jsonResult = userService.loginThroughStudent(loginUserVo);
        } else {
            return JsonResult.buildFailure(404,"权限格式不合法");
        }
        return jsonResult;
    }
}
